# -*- coding: utf-8 -*-
"""
Created on Mon Mar 11 17:36:31 2024

@author: heyuesong
"""

import pandas as pd
import requests

import base64


"""
## hook eval

my_eval = eval;
eval = function () {
    if(arguments[0].indexOf('debugger') != -1){
        return function(){}
    };
    return my_eval(arguments[0])
}


## hook appendChild

_appendChild = Node.prototype.appendChild
Node.prototype.appendChild = function(){
        if(arguments[0].innerHTML && arguments[0].innerHTML.indexOf('debugger') != -1){
            arguments[0].innerHTML = ''
        }
        return _appendChild.apply(this,arguments)
    }


## hook Function

_Function = Function
Function.prototype.constructor = function(){
    if(arguments[0].indexOf('debugger')!= -1){
        arguments[0] = ''
    }
    return _Function.apply(this,arguments)
}

"""







result_list = []
for i in range(1,101):
    print(i)
    Session = requests.session()
    
    headers={
        "Host": "www.python-spider.com",
        "Connection": "keep-alive",
        "Content-Length": "6",
        "sec-ch-ua": "\"Chromium\";v=\"122\", \"Not(A:Brand\";v=\"24\", \"Google Chrome\";v=\"122\"",
        "Accept": "application/json, text/javascript, */*; q=0.01",
        "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8",
        "X-Requested-With": "XMLHttpRequest",
        "sec-ch-ua-mobile": "?0",
        "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36",
        "sec-ch-ua-platform": "\"Windows\"",
        "Origin": "https://www.python-spider.com",
        "Sec-Fetch-Site": "same-origin",
        "Sec-Fetch-Mode": "cors",
        "Sec-Fetch-Dest": "empty",
        "Referer": "https://www.python-spider.com/challenge/54",
        "Accept-Encoding": "gzip, deflate, br, zstd",
        "Accept-Language": "zh-CN,zh;q=0.9"
    }
    
    cookies = {
        "Hm_lvt_337e99a01a907a08d00bed4a1a52e35d": "1709706135,1709706247",
        "m": "1f32318d5514eff050f4673ce6333944|1709715126000",
        "no-alert": "true",
        "sign": "zoyubwiehj",
        "_i": "em95dWJ3aWVoag",
        "_v": "ZW05NWRXSjNhV1ZvYWc",
        "Hm_lpvt_337e99a01a907a08d00bed4a1a52e35d": "1710147962"
    }
    url =  "https://www.python-spider.com/api/challenge54"
    data = {
        "page": str(i),
        "token": base64.b64encode(str(i).encode()).decode()
    }
    Session.headers.clear()
    Session.headers.update(headers)
    Session.cookies.update( cookies)
    
    
    response = Session.post(url,data=data)
    html = response.json()['data']
    result_list+=html
result_df = pd.DataFrame(result_list)

result_df['value'] = result_df['value'].apply(lambda x:int(x.replace('\r','')))


print(sum(result_df['value']))